package test._1027;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Student implements Comparable<Student> {
    public String name;
    public int score;
    public int num;

    public Student(String name, int score, int num) {
        this.name = name;
        this.score = score;
        this.num = num;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", num=" + num +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if (this.score != o.score) {
            return o.score - this.score;
        } else {
            return this.num - o.num;
        }
    }




    public static void main(String[] args) {
        Student s1 = new Student("张三", 100, 1);
        Student s2 = new Student("李四", 88, 2);
        Student s3 = new Student("王五", 88, 35);
        Student s4 = new Student("赵六", 88, 4);

        List<Student> students = new ArrayList<>();

        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);

        Collections.sort(students);

        Iterator<Student> iterator = students.iterator();

        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
